package cn.myjerry.test.ORM;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 使用Object[] 封装一条数据
 * 使用List<Object[]>存储多条数据
 * @author Jerry
 *
 */
public class Demo01 {
	public static void main(String[] args) {
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet res = null;
		List<Object[]> list = new ArrayList<>();

		try {
			conn = JDBCUtil.getMysqlConn();
			ps = conn.prepareStatement("SELECT Name,Salary,Age FROM Employee WHERE Id > ?");
			ps.setInt(1, 0);
			res = ps.executeQuery();
			while (res.next()) {
				Object[] objs = new Object[3];
				// System.out.println(res.getString("Name") + "==>" + res.getDouble("Salary") +
				// "==>" + res.getInt("Age"));
				objs[0] = res.getString("Name");
				objs[1] = res.getDouble("Salary");
				objs[2] = res.getInt("Age");
				
				list.add(objs);
			}

		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			JDBCUtil.close(res, ps, conn);
		}
		
		for(Object[] objs:list) {
			System.out.println(Arrays.toString(objs));
		}
	}
}
